package com.example.allshengmedical.experimentanalyze.activity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Environment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.allshengmedical.R;
import com.example.allshengmedical.base.BaseApplication;
import com.example.allshengmedical.base.BaseFragment;
import com.example.allshengmedical.experimentanalyze.activity.MedicalFragment.DragGridViewAdapter;
import com.example.allshengmedical.experimentanalyze.activity.MedicalFragment.RecyclerViewAdapter;
import com.example.allshengmedical.experimentanalyze.activity.MedicalFragment.StandardListViewAdapter;
import com.example.allshengmedical.experimentanalyze.activity.MedicalFragment.DragGridViewAdapter.ViewHolder;
import com.example.allshengmedical.experimentanalyze.activity.MedicalFragment.RecyclerViewAdapter.MyViewHolder;
import com.example.allshengmedical.experimentnew.bean.LayoutTableBean;
import com.example.allshengmedical.experimentnew.bean.MethodBean;
import com.example.allshengmedical.util.ByAlert;
import com.example.allshengmedical.util.DragGridView;
import com.example.allshengmedical.util.FileManagerUtil;
import com.example.allshengmedical.util.ListViewForScrollView;
import com.example.allshengmedical.util.LogUtil;
import com.example.allshengmedical.util.MyHorizontalScrollView;
import com.example.allshengmedical.util.ScrollViewListener;
import com.example.allshengmedical.util.SharedPreferencesUtils;
import com.example.allshengmedical.util.SimpleLineChart;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfWriter;

//科研报告
public class ResearchFragment extends BaseFragment implements
		ScrollViewListener {
	private TextView experimentNameET, experimentIdEt, experimenterEt,
			spinnerExperType, spinnerSampleType, spinnerReagent,spinnerPassReference;

	// LayoutOne信息的配置
	private ListViewForScrollView standardInfoLv;
	private StandardListViewAdapter standardListViewAdapter;
	private ArrayList<LayoutTableBean> activityLayoutTableBeans;

	// 基因盘
	private DragGridView dragGridView1, dragGridView2;
	private DragGridViewAdapter dragGridViewAdapter;

	FileManagerUtil fileManagerUtil;

	// 数据
	String folderName;
	String fileName;
	private String appFilePath = Environment.getExternalStorageDirectory()
			+ "/" + "AllShengMedical";
	StringBuffer contextString = new StringBuffer();

	public List<HashMap<String, Object>> dataSourceListBlock1 = new ArrayList<HashMap<String, Object>>();
	public List<HashMap<String, Object>> dataSourceListBlock2 = new ArrayList<HashMap<String, Object>>();

	// 曲线图
	// 上半部
	private RecyclerView steptRv;
	private RecyclerViewAdapter recyclerViewAdapter;
	private ArrayList<MethodBean> activityMethodBeans;

	// 下半部分
	private SimpleLineChart mSimpleLineChart;

	// 下面的图表
	HashMap<Integer, Integer> pointMap = new HashMap();
	List<HashMap<String, Object>> pointMaps = new ArrayList<HashMap<String, Object>>();

	private String[] xItem, yItem = { "", "", "", "", "", "", "", "", "", "",
			"" };

	// 下面的横划
	MyHorizontalScrollView downScrollView, upScrollView;

	Button createPDF;
	LinearLayout line;

	@Override
	public int getlayout() {
		// TODO Auto-generated method stub
		return R.layout.fragment_medical;
	}

	@Override
	protected void initView() {
		// TODO Auto-generated method stub
		downScrollView = BindView(R.id.downScrollView);
		downScrollView.setScrollViewListener(this);
		upScrollView = BindView(R.id.upScrollView);
		upScrollView.setScrollViewListener(this);
		experimentNameET = BindView(R.id.experimentNameET);
		experimentIdEt = BindView(R.id.experimentIdEt);
		experimenterEt = BindView(R.id.experimenterEt);
		spinnerExperType = BindView(R.id.spinnerExperType);
		spinnerSampleType = BindView(R.id.spinnerSampleType);
		spinnerReagent = BindView(R.id.spinnerReagent);
		experimentIdEt = BindView(R.id.experimentIdEt);
		standardInfoLv = BindView(R.id.standardInfoLv);
		dragGridView1 = BindView(R.id.dragGridView1);
		dragGridView2 = BindView(R.id.dragGridView2);
		spinnerPassReference= BindView(R.id.spinnerPassReference);

		fileManagerUtil = new FileManagerUtil();
		getInfo();
		initBaseInformation();
		initLayoutOne();
		initGene();
		initSimpleLineChart();
		dragGridView1.isDrag = false;
		dragGridView2.isDrag = false;

		createPDF.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				fileName = SharedPreferencesUtils.get(getActivity(),
						BaseApplication.FILEMANGER_PREPAREFILENAME, "") + "";

				String filePath = Environment.getExternalStorageDirectory()
						+ "/" + "AllShengReport" + "/" + "[Research]"
						+ fileName.substring(0, fileName.length() - 4) + ".pdf";

				// String imagePath = "d:\\test.bmp";

				// 先创建一个Document文档对象

				Document document = new Document();

				try {

					// 生成test.pdf文档

					PdfWriter.getInstance(document, new FileOutputStream(
							filePath));

					// 添加PDF文档的某些信息，比如作者，主题等等

					document.addAuthor("zouwei");

					document.addSubject("test pdf....");

					// 设置文档的大小

					document.setPageSize(PageSize.A2);

					// 打开文档

					document.open();

					// 写入一段文字

					// document.add(new Paragraph("JUST TEST ..."));

					// 读取一个图片

					Image image = Image.getInstance(viewSaveToImage(line));

					// 插入一个图片

					document.add(image);

				} catch (DocumentException de) {

					System.out.println(de.getMessage());

				} catch (IOException ioe) {

					System.out.println(ioe.getMessage());

				}

				// 关闭打开的pdf文档

				document.close();

				ByAlert.alert(getString(R.string.report_pdfcreat));
			}
		});

	}

	@Override
	protected void dataView() {
		// TODO Auto-generated method stub

	}

	public void getInfo() {
		folderName = SharedPreferencesUtils.get(getActivity(),
				BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "") + "";
		fileName = SharedPreferencesUtils.get(getActivity(),
				BaseApplication.FILEMANGER_PREPAREFILENAME, "") + "";

		String path = appFilePath + "/" + folderName;

		File file = new File(path + "/" + fileName);
		FileInputStream in =null;
		BufferedReader reader=null;
		contextString=new StringBuffer();
		try {
			in =new FileInputStream(file);
			reader=new BufferedReader(new InputStreamReader(in));
			String line ="";
			while((line =reader.readLine())!=null){
				contextString.append(line);
				contextString.append(",");
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if(reader != null){
				try {
					reader.close();
				} catch (Exception e2) {
					e2.printStackTrace();
				}
			}
		}
//		BufferedReader reader = null;
//		contextString=new StringBuffer();
//		System.gc();
//		try {
//			System.out.println("以行为单位读取文件内容，一次读一整行:");
//			reader = new BufferedReader(new FileReader(file));
//			String tempString = null;
//			int line = 1;
//			// 一次读入一行，直到读入null为文件结束
//			while ((tempString = reader.readLine()) != null) {
//				// 显示行号
//				// System.out.println("line " + line + ": " + tempString);
//				// Log.e("--", tempString);
//				contextString.append(tempString);
//				contextString.append(",");
//				line++;
//			}
//			reader.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			if (reader != null) {
//				try {
//					reader.close();
//					LogUtil.e("!!", contextString + "");
//
//				} catch (IOException e1) {
//				}
//			}
//		}
	}

	public void initBaseInformation() {

		String experimentName = contextString.substring(
				contextString.indexOf("ExperimentName:") + 15,
				contextString.indexOf(",ExperimentID:"));
		// 实验名称
		// LogUtil.e(experimentName);

		String experimentNum = contextString.substring(
				contextString.indexOf("ExperimentID:") + 13,

				contextString.indexOf(",Experimenter:"));
		// 实验编号
		// LogUtil.e(experimentNum);

		String experimenter = contextString.substring(
				contextString.indexOf("Experimenter:") + 13,

				contextString.indexOf(",ExperimentType:"));
		// 实验人员
		// LogUtil.e(experimenter);

		String ExperimentType = contextString.substring(
				contextString.indexOf("ExperimentType:") + 15,

				contextString.indexOf(",SampleType:"));
		// 实验类型
		// LogUtil.e(ExperimentType);

		String SampleType = contextString.substring(
				contextString.indexOf("SampleType:") + 11,

				contextString.indexOf(",Reagent:"));
		// 样品类型
		// LogUtil.e(SampleType);

		String Reagent = contextString.substring(contextString.indexOf("Reagent:") + 8,

				contextString.indexOf(",PassReference"));
				// 试剂
				// LogUtil.e(Reagent);

		// reference
		String PassReference = contextString.substring(contextString.indexOf("PassReference:") + 14,

				contextString.indexOf(",,"));
		// 试剂
		// LogUtil.e(Reagent);

		experimentNameET.setText(experimentName);
		experimentIdEt.setText(experimentNum);
		experimenterEt.setText(experimenter);
		spinnerExperType.setText(ExperimentType);
		spinnerSampleType.setText(SampleType);
		spinnerReagent.setText(Reagent);
		spinnerPassReference.setText(PassReference);
	}

	public void initLayoutOne() {
		activityLayoutTableBeans = new ArrayList<LayoutTableBean>();

		// LogUtil.e(contextString.indexOf(",Aisle") + 7);
		// LogUtil.e(contextString.indexOf(",Color"));

		int index = 0;
		while (!(contextString.indexOf("Aisle", index) <= 0)) {

			// Aisle:
			String aisle;
			aisle = contextString.substring(
					contextString.indexOf(",Aisle", index) + 7,

					contextString.indexOf(",Color", index));
			// LogUtil.e(aisle);

			// Color
			String color;
			color = contextString.substring(
					contextString.indexOf(",Color", index) + 7,

					contextString.indexOf(",Target", index));
			// LogUtil.e(color);

			// Target
			String target;
			target = contextString.substring(
					contextString.indexOf(",Target", index) + 8,

					contextString.indexOf(",Dyes", index));

			// LogUtil.e(target);

			int nextIndex = contextString.indexOf(",Aisle", index) + 7;

			// Dyes
			String dyes;
			if (contextString.indexOf(",Aisle", nextIndex) < 0) {

				dyes = contextString.substring(
						contextString.indexOf(",Dyes", index) + 6,
						contextString.indexOf(",,dataSourceListBlock1", index));

				// LogUtil.e(dyes);
			} else {

				dyes = contextString.substring(
						contextString.indexOf(",Dyes", index) + 6,

						contextString.indexOf(",Aisle", nextIndex));
				// LogUtil.e(dyes);
			}

			index = contextString.indexOf(",Dyes", index) + 5;

			activityLayoutTableBeans.add(new LayoutTableBean(false, Integer
					.parseInt(aisle.trim()), Integer.parseInt(color.trim()),
					target, dyes));

		}

		standardListViewAdapter = new StandardListViewAdapter(
				activityLayoutTableBeans);
		standardInfoLv.setAdapter(standardListViewAdapter);

	}

	public void initGene() {
		// dataSourceListBlock1.add((HashMap<String, Object>)
		// Arrays.asList(contextString.substring(
		// contextString.indexOf(",[{") + 2,
		// contextString.indexOf("}]") + 2)));

		// int index = contextString.indexOf("}]") + 3;
		int index = 0;

		for (int i = 0; i < 16; i++) {
			HashMap<String, Object> hashMap = new HashMap<String, Object>();
			String item_image = contextString.substring(
					contextString.indexOf("item_image:", index) + 11,
					contextString.indexOf(",item_text:", index)).trim();
			String item_text = contextString.substring(
					contextString.indexOf("item_text:", index) + 10,
					contextString.indexOf(",item_selected:", index)).trim();
			Boolean item_selected = Boolean.getBoolean(contextString.substring(
					contextString.indexOf("item_selected:", index) + 14,
					contextString.indexOf(",item_null:", index)));

			boolean item_null = false;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_null:", index) + 10,
					contextString.indexOf(",item_aisle:", index)))) {
				item_null = true;
				hashMap.put("item_null", item_null);
			} else {
				item_null = false;
				hashMap.put("item_null", item_null);
			}
			// = contextString.substring(
			// contextString.indexOf("item_null:", index) + 10,
			// contextString.indexOf(",item_aisle:", index));
			int item_aisle = 0;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_aisle:", index) + 11,
					contextString.indexOf(",item_type:", index)).trim())) {

			} else {
				item_aisle = Integer.parseInt(contextString.substring(
						contextString.indexOf("item_aisle:", index) + 11,
						contextString.indexOf(",item_type:", index)).trim());
			}

			// String item_type = contextString.substring(
			// contextString.indexOf("item_type:", index) + 11,
			// contextString.indexOf("item_type:", index));

			int nextIndex = contextString.indexOf("item_image:", index) + 11;

			String item_type = "";
			if (i == 15) {
				item_type = contextString.substring(
						contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",,dataSourceListBlock2", index))
						.trim();
			} else {
				item_type = contextString.substring(
						contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",item_image:", nextIndex))
						.trim();
			}

			LogUtil.e(item_image);
			LogUtil.e(item_text);
			LogUtil.e(item_selected);
			// LogUtil.e(item_null+"");
			// LogUtil.e(item_aisle+"");
			LogUtil.e(item_type);

			hashMap.put("item_image", item_image);
			hashMap.put("item_text", item_text);
			hashMap.put("item_selected", item_selected);

			hashMap.put("item_aisle", item_aisle);
			hashMap.put("item_type", item_type);

			dataSourceListBlock1.add(hashMap);
			index = contextString.indexOf("item_type:", index) + 10;
		}

		LogUtil.e(dataSourceListBlock1);
		dragGridViewAdapter = new DragGridViewAdapter(dataSourceListBlock1);

		dragGridView1.setAdapter(dragGridViewAdapter);

		index = contextString.indexOf("dataSourceListBlock2");

		for (int i = 0; i < 16; i++) {
			HashMap<String, Object> hashMap = new HashMap<String, Object>();
			String item_image = contextString.substring(
					contextString.indexOf("item_image:", index) + 11,
					contextString.indexOf(",item_text:", index)).trim();
			String item_text = contextString.substring(
					contextString.indexOf("item_text:", index) + 10,
					contextString.indexOf(",item_selected:", index)).trim();
			Boolean item_selected = Boolean.getBoolean(contextString.substring(
					contextString.indexOf("item_selected:", index) + 14,
					contextString.indexOf(",item_null:", index)));

			boolean item_null = false;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_null:", index) + 10,
					contextString.indexOf(",item_aisle:", index)))) {
				item_null = true;
				hashMap.put("item_null", item_null);
			} else {
				item_null = false;
				hashMap.put("item_null", item_null);
			}
			// = contextString.substring(
			// contextString.indexOf("item_null:", index) + 10,
			// contextString.indexOf(",item_aisle:", index));
			int item_aisle = 0;
			if ("null".equals(contextString.substring(
					contextString.indexOf("item_aisle:", index) + 11,
					contextString.indexOf(",item_type:", index)).trim())) {

			} else {
				item_aisle = Integer.parseInt(contextString.substring(
						contextString.indexOf("item_aisle:", index) + 11,
						contextString.indexOf(",item_type:", index)).trim());
			}

			// String item_type = contextString.substring(
			// contextString.indexOf("item_type:", index) + 11,
			// contextString.indexOf("item_type:", index));

			int nextIndex = contextString.indexOf("item_image:", index) + 11;

			String item_type = "";
			if (contextString.indexOf("item_image:", nextIndex) < 0) {
				item_type = contextString.substring(
						contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",,cameraSet", index)).trim();
				LogUtil.e(item_type);

			} else {

				item_type = contextString.substring(
						contextString.indexOf("item_type:", index) + 10,
						contextString.indexOf(",item_image:", nextIndex))
						.trim();
			}

			LogUtil.e(item_image);
			LogUtil.e(item_text);
			LogUtil.e(item_selected);
			// LogUtil.e(item_null+"");
			// LogUtil.e(item_aisle+"");
			LogUtil.e(item_type);

			hashMap.put("item_image", item_image);
			hashMap.put("item_text", item_text);
			hashMap.put("item_selected", item_selected);

			hashMap.put("item_aisle", item_aisle);
			hashMap.put("item_type", item_type);

			dataSourceListBlock2.add(hashMap);
			index = contextString.indexOf("item_type:", index) + 10;
		}

		LogUtil.e(dataSourceListBlock2);
		dragGridViewAdapter = new DragGridViewAdapter(dataSourceListBlock2);

		dragGridView2.setAdapter(dragGridViewAdapter);

	}

	public void initSimpleLineChart() {
		initSimpleLineChartView();

	}

	public class StandardListViewAdapter extends BaseAdapter {
		private ArrayList<LayoutTableBean> layoutTableBeans;

		public StandardListViewAdapter(
				ArrayList<LayoutTableBean> layoutTableBeans) {
			super();
			this.layoutTableBeans = layoutTableBeans;
		}

		public void removeBean(Object layoutTableBean) {
			layoutTableBeans.remove(layoutTableBean);
			activityLayoutTableBeans.remove(layoutTableBean);
			notifyDataSetChanged();

		}

		class ViewHolder {
			TextView numTv, targetTv, aisleTv;
			CheckBox checkBox;
			ImageView colorIv;
			TextView fluorescentSpinner;
		}

		@Override
		public int getCount() {
			return layoutTableBeans != null ? layoutTableBeans.size() : 0;
		}

		@Override
		public Object getItem(int position) {
			return layoutTableBeans != null ? layoutTableBeans.get(position)
					: null;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			final ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(getActivity()).inflate(
						R.layout.item_listview_preview_standard, null);
				holder.aisleTv = (TextView) convertView
						.findViewById(R.id.aisleTv);
				holder.checkBox = (CheckBox) convertView
						.findViewById(R.id.checkBox);
				holder.colorIv = (ImageView) convertView
						.findViewById(R.id.colorIv);
				holder.fluorescentSpinner = (TextView) convertView
						.findViewById(R.id.fluorescentSpinner);
				holder.numTv = (TextView) convertView.findViewById(R.id.numTv);
				holder.targetTv = (TextView) convertView
						.findViewById(R.id.targetTv);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			if (layoutTableBeans.get(position).getChoseen()) {
				holder.checkBox.setChecked(true);
			}
			if (activityLayoutTableBeans.get(position).getColor() == 0) {
				holder.colorIv.setBackground(getResources().getDrawable(
						R.color.white));
			} else {
				switch (activityLayoutTableBeans.get(position).getColor()) {
				case 11:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_one));
					break;
				case 12:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_two));
					break;
				case 13:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_three));

					break;
				case 14:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_four));

					break;
				case 15:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_five));

					break;
				case 16:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_six));

					break;
				case 21:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_one));
					break;
				case 22:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_two));
					break;
				case 23:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_three));
					break;
				case 24:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_four));
					break;
				case 25:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_five));
					break;
				case 26:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_six));
					break;
				case 31:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_one));
					break;
				case 32:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_two));
					break;
				case 33:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_three));
					break;
				case 34:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_four));
					break;
				case 35:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_five));
					break;
				case 36:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_six));
					break;

				case 41:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_one));
					break;
				case 42:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_two));
					break;
				case 43:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_three));
					break;
				case 44:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_four));
					break;
				case 45:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_five));
					break;
				case 46:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_six));
					break;
				case 51:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_one));
					break;
				case 52:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_two));
					break;
				case 53:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_three));
					break;
				case 54:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_four));
					break;
				case 55:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_five));
					break;
				case 56:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_six));
					break;
				case 61:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_one));
					break;
				case 62:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_two));

					break;
				case 63:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_three));
					break;
				case 64:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_four));
					break;
				case 65:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_five));
					break;
				case 66:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_six));
					break;
				default:
					break;
				}
			}

			holder.numTv.setText(position + 1 + "");

			holder.fluorescentSpinner.setText(layoutTableBeans.get(position)
					.getFluorescentDyes() + "");
			if ("1".equals(layoutTableBeans.get(position).getAisle())) {
				holder.aisleTv.setText("1:470/525nm");
			} else if ("2".equals(layoutTableBeans.get(position).getAisle())) {
				holder.aisleTv.setText("2:530/571nm");
			} else if ("3".equals(layoutTableBeans.get(position).getAisle())) {
				holder.aisleTv.setText("3:571/612nm");
			} else if ("4".equals(layoutTableBeans.get(position).getAisle())) {
				holder.aisleTv.setText("4:620/680nm");
			}

			holder.targetTv.setText(layoutTableBeans.get(position).getTarget());

			holder.checkBox.setVisibility(View.GONE);

			return convertView;
		}
	}

	public class DragGridViewAdapter extends BaseAdapter {
		List<HashMap<String, Object>> dataSourceListBlock = new ArrayList<HashMap<String, Object>>();

		public DragGridViewAdapter(
				List<HashMap<String, Object>> dataSourceListBlock) {
			super();
			this.dataSourceListBlock = dataSourceListBlock;
		}

		public void changeList(List<HashMap<String, Object>> dataSourceListBlock) {

			this.dataSourceListBlock = dataSourceListBlock;
			notifyDataSetChanged();
		}

		class ViewHolder {

			LinearLayout line, textViewLine;
			ImageView item_image;
			TextView item_text, aisle1, aisle2, aisle3, aisle4;

		}

		@Override
		public int getCount() {
			return dataSourceListBlock != null ? dataSourceListBlock.size() : 0;
		}

		@Override
		public Object getItem(int position) {
			return dataSourceListBlock != null ? dataSourceListBlock
					.get(position) : null;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			final ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(getActivity()).inflate(
						R.layout.item_layout2_grid, null);

				holder.line = (LinearLayout) convertView
						.findViewById(R.id.line);
				holder.item_image = (ImageView) convertView
						.findViewById(R.id.item_image);
				holder.item_text = (TextView) convertView
						.findViewById(R.id.item_text);
				holder.aisle1 = (TextView) convertView
						.findViewById(R.id.aisle1);
				holder.aisle2 = (TextView) convertView
						.findViewById(R.id.aisle2);
				holder.aisle3 = (TextView) convertView
						.findViewById(R.id.aisle3);
				holder.aisle4 = (TextView) convertView
						.findViewById(R.id.aisle4);
				holder.textViewLine = (LinearLayout) convertView
						.findViewById(R.id.textViewLine);

				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.aisle1.setVisibility(View.VISIBLE);
			holder.aisle2.setVisibility(View.VISIBLE);
			holder.aisle3.setVisibility(View.VISIBLE);
			holder.aisle4.setVisibility(View.VISIBLE);
			holder.textViewLine.setBackground(getResources().getDrawable(
					R.color.darkBlue));

			if (dataSourceListBlock.get(position).get("item_aisle") != null) {
				if (!TextUtils.isEmpty(dataSourceListBlock.get(position).get(
						"item_aisle")
						+ "")) {

					if (Integer.parseInt(dataSourceListBlock.get(position)
							.get("item_aisle").toString()) != 0) {
						int aisleNum = (Integer) dataSourceListBlock.get(
								position).get("item_aisle");
						holder.textViewLine.setVisibility(View.VISIBLE);
						holder.aisle1.setVisibility(View.VISIBLE);
						holder.aisle2.setVisibility(View.VISIBLE);
						holder.aisle3.setVisibility(View.VISIBLE);
						holder.aisle4.setVisibility(View.VISIBLE);
						switch (aisleNum) {
						case 1:
							setcolor(holder.aisle1, position,
									holder.textViewLine);
							holder.aisle2.setBackground(getResources()
									.getDrawable(R.color.white));
							holder.aisle3.setBackground(getResources()
									.getDrawable(R.color.white));
							holder.aisle4.setBackground(getResources()
									.getDrawable(R.color.white));

							break;
						case 2:
							holder.aisle1.setBackground(getResources()
									.getDrawable(R.color.white));
							setcolor(holder.aisle2, position,
									holder.textViewLine);
							holder.aisle3.setBackground(getResources()
									.getDrawable(R.color.white));
							holder.aisle4.setBackground(getResources()
									.getDrawable(R.color.white));

							break;

						case 3:
							holder.aisle1.setBackground(getResources()
									.getDrawable(R.color.white));
							holder.aisle2.setBackground(getResources()
									.getDrawable(R.color.white));
							setcolor(holder.aisle3, position,
									holder.textViewLine);
							holder.aisle4.setBackground(getResources()
									.getDrawable(R.color.white));
							break;

						case 4:
							holder.aisle1.setBackground(getResources()
									.getDrawable(R.color.white));
							holder.aisle2.setBackground(getResources()
									.getDrawable(R.color.white));
							holder.aisle3.setBackground(getResources()
									.getDrawable(R.color.white));
							setcolor(holder.aisle4, position,
									holder.textViewLine);
							break;

						default:
							break;
						}
					} else {
						holder.textViewLine.setVisibility(View.INVISIBLE);
						holder.aisle1.setVisibility(View.INVISIBLE);
						holder.aisle2.setVisibility(View.INVISIBLE);
						holder.aisle3.setVisibility(View.INVISIBLE);
						holder.aisle4.setVisibility(View.INVISIBLE);
					}

				} else {
					holder.textViewLine.setVisibility(View.INVISIBLE);
					holder.aisle1.setVisibility(View.INVISIBLE);
					holder.aisle2.setVisibility(View.INVISIBLE);
					holder.aisle3.setVisibility(View.INVISIBLE);
					holder.aisle4.setVisibility(View.INVISIBLE);
				}
			}

			holder.line
					.setBackground(getResources().getDrawable(R.color.white));

			// map.put("item_type", "positive");

			if ("sample".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackgroundColor(Color
						.parseColor("#ff2d55"));
			} else if ("standard".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackgroundColor(Color
						.parseColor("#fd9727"));
			} else if ("positive".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackgroundColor(Color
						.parseColor("#ff00a9"));
			} else if ("negative".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackgroundColor(Color
						.parseColor("#159588"));
			} else if (dataSourceListBlock.get(position).get("item_image") == null) {
				holder.item_image.setBackground(getResources().getDrawable(
						R.color.white));
			} else if ("".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackground(getResources().getDrawable(
						R.color.white));
			} else {
				holder.item_image.setBackground(getResources().getDrawable(
						R.color.white));
			}

			// if
			// ("".equals(dataSourceListBlock.get(position).get("item_image")))
			// {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.white));
			// } else if ("11".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_one));
			// } else if ("12".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_two));
			// } else if ("13".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_three));
			// } else if ("14".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_four));
			// } else if ("15".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_five));
			// } else if ("16".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_six));
			// } else if ("21".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_one));
			// } else if ("22".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_two));
			// } else if ("23".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_three));
			// } else if ("24".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_four));
			// } else if ("25".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_five));
			// } else if ("26".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_six));
			// } else if ("31".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_one));
			// } else if ("32".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_two));
			// } else if ("33".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_three));
			// } else if ("34".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_four));
			// } else if ("35".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_five));
			// } else if ("36".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_six));
			// } else if ("41".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_one));
			// } else if ("42".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_two));
			// } else if ("43".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_three));
			// } else if ("44".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_four));
			// } else if ("45".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_five));
			// } else if ("46".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_six));
			// } else if ("51".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_one));
			// } else if ("52".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_two));
			// } else if ("53".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_three));
			// } else if ("54".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_four));
			// } else if ("55".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_five));
			// } else if ("56".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_six));
			// } else if ("61".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_one));
			// } else if ("62".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_two));
			// } else if ("63".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_three));
			// } else if ("64".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_four));
			// } else if ("65".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_five));
			// } else if ("66".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_six));
			// }
			holder.item_text.setText(dataSourceListBlock.get(position).get(
					"item_text")
					+ "");

			return convertView;
		}

		private void setcolor(TextView aisle, int position,
				LinearLayout textViewLine) {
			if ("".equals(dataSourceListBlock.get(position).get("item_image")
					.toString().trim())) {
				aisle.setBackground(getResources().getDrawable(R.color.white));
				// textViewLine.setVisibility(View.INVISIBLE);
				textViewLine.setBackground(getResources().getDrawable(
						R.color.white));
			} else if ("11".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_one));
			} else if ("12".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_two));
			} else if ("13".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_three));
			} else if ("14".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_four));
			} else if ("15".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_five));
			} else if ("16".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_six));
			} else if ("21".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_one));
			} else if ("22".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_two));
			} else if ("23".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_three));
			} else if ("24".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_four));
			} else if ("25".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_five));
			} else if ("26".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_six));
			} else if ("31".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_one));
			} else if ("32".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_two));
			} else if ("33".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_three));
			} else if ("34".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_four));
			} else if ("35".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_five));
			} else if ("36".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_six));
			} else if ("41".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_one));
			} else if ("42".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_two));
			} else if ("43".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_three));
			} else if ("44".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_four));
			} else if ("45".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_five));
			} else if ("46".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_six));
			} else if ("51".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_one));
			} else if ("52".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_two));
			} else if ("53".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_three));
			} else if ("54".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_four));
			} else if ("55".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_five));
			} else if ("56".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_six));
			} else if ("61".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_one));
			} else if ("62".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_two));
			} else if ("63".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_three));
			} else if ("64".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_four));
			} else if ("65".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_five));
			} else if ("66".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_six));
			} else if (dataSourceListBlock.get(position).get("item_image") == null) {
				aisle.setBackground(getResources().getDrawable(R.color.white));
				// textViewLine.setVisibility(View.INVISIBLE);

			} else {
				aisle.setBackground(getResources().getDrawable(R.color.white));
				// textViewLine.setVisibility(View.INVISIBLE);
				aisle.setBackground(getResources().getDrawable(R.color.white));
			}

		}
	}

	private void initSimpleLineChartView() {
		activityMethodBeans = new ArrayList<MethodBean>();

		int index = contextString.indexOf("Methods");
		// 上面解析
		while (!(contextString.indexOf("steptType:", index) <= 0)) {

			// steptType:
			String steptType;
			steptType = contextString.substring(
					contextString.indexOf("steptType:", index) + 10,

					contextString.indexOf(",temperature:", index));

			// LogUtil.e(steptType);

			// temperature
			String temperature;
			temperature = contextString.substring(
					contextString.indexOf(",temperature:", index) + 13,

					contextString.indexOf(",time:", index));

			// LogUtil.e(temperature);
			// time
			String time;
			time = contextString.substring(
					contextString.indexOf(",time:", index) + 6,

					contextString.indexOf(",goTo:", index));
			// LogUtil.e(time);

			// goTo
			String goTo;
			goTo = contextString.substring(
					contextString.indexOf(",goTo:", index) + 6,

					contextString.indexOf(",Repititions:", index));
			// LogUtil.e(goTo);
			// Repititions
			String repititions;
			repititions = contextString.substring(
					contextString.indexOf(",Repititions:", index) + 13,

					contextString.indexOf(",deltaT:", index));
			// LogUtil.e(repititions);
			// deltaT
			String deltaT;
			deltaT = contextString.substring(
					contextString.indexOf(",deltaT:", index) + 8,

					contextString.indexOf(",rightSelect:", index));
			// LogUtil.e(deltaT);

			int nextIndex = contextString.indexOf("steptType:", index) + 10;

			// rightSelect
			String rightSelect;

			if (contextString.indexOf(",steptType:", nextIndex) < 0) {
				rightSelect = contextString.substring(
						contextString.indexOf(",rightSelect:", index) + 13,
						contextString.indexOf(",,pointMap", index));
				if ("null".equals(rightSelect)) {
					rightSelect = "";
				}

			} else {
				rightSelect = contextString.substring(
						contextString.indexOf(",rightSelect:", index) + 13,

						contextString.indexOf(",steptType:", nextIndex));
				if ("null".equals(rightSelect)) {
					rightSelect = "";
				}
			}
			// LogUtil.e(rightSelect);
			index = contextString.indexOf(",rightSelect:", index) + 13;

			activityMethodBeans.add(new MethodBean(steptType.trim(),
					temperature.trim(), time.trim(), goTo.trim(), repititions
							.trim(), deltaT.trim()));
		}
		// 上面配置完成
		steptRv = BindView(R.id.steptRv);
		LayoutManager layoutManager = new GridLayoutManager(getActivity(), 1);
		((GridLayoutManager) layoutManager)
				.setOrientation(OrientationHelper.HORIZONTAL);
		steptRv.setLayoutManager(layoutManager);
		recyclerViewAdapter = new RecyclerViewAdapter(activityMethodBeans);
		steptRv.setAdapter(recyclerViewAdapter);

		// 下面解析
		int num = 1;
		pointMap = new HashMap<Integer, Integer>();
		if (contextString.indexOf(",,Channel1") > 0) {
			// 已经有实验数据的实验
			while (!(contextString.indexOf("pointMap", index) <= 0)) {

				int pointMapValue = 0;
				// int nextIndex = contextString.indexOf("pointMap", index);

				if (contextString.indexOf("pointMap" + num) < 0) {
					// pointMap = Integer
					// .parseInt(contextString.substring(contextString
					// .indexOf("pointMap"+num, index) + 10));

				} else {
					if (contextString.indexOf("pointMap" + (num + 1)) < 0) {
						// pointMap = Integer.parseInt(contextString
						// .substring(
						// contextString.indexOf("pointMap:" + num,
						// index) + 9).trim());
						if (num < 10) {
							pointMapValue =10- Integer
									.parseInt(contextString
											.substring(
													contextString
															.indexOf("pointMap"
																	+ num) + 11,
													contextString
															.indexOf(",,Raw Data"))
											.trim());
						} else {
							pointMapValue = 10-Integer
									.parseInt(contextString
											.substring(
													contextString
															.indexOf("pointMap"
																	+ num) + 11,
													contextString
															.indexOf(",,Raw Data"))
											.trim());
						}

						LogUtil.e(pointMapValue);
						pointMap.put(num - 1, pointMapValue);
						break;

					} else {

						if (num < 10) {
							pointMapValue =10- Integer.parseInt(contextString
									.substring(
											contextString.indexOf("pointMap"
													+ num) + 10,
											contextString.indexOf(",pointMap"
													+ (num + 1))).trim());
						} else {
							pointMapValue = 10-Integer.parseInt(contextString
									.substring(
											contextString.indexOf("pointMap"
													+ num) + 11,
											contextString.indexOf(",pointMap"
													+ (num + 1))).trim());
						}

					}

				}
				pointMap.put(num - 1, pointMapValue);
				num++;
				index = contextString.indexOf("pointMap", index);
				LogUtil.e(pointMapValue);

			}
		} else {
			while (!(contextString.indexOf("pointMap", index) <= 0)) {

				int pointMapValue = 0;
				// int nextIndex = contextString.indexOf("pointMap", index);

				if (contextString.indexOf("pointMap" + num) < 0) {
					// pointMap = Integer
					// .parseInt(contextString.substring(contextString
					// .indexOf("pointMap"+num, index) + 10));

				} else {
					if (contextString.indexOf("pointMap" + (num + 1)) < 0) {
						// pointMap = Integer.parseInt(contextString
						// .substring(
						// contextString.indexOf("pointMap:" + num,
						// index) + 9).trim());
						if (num < 10) {
							pointMapValue =10- Integer.parseInt(contextString
									.substring(
											contextString.indexOf("pointMap"
													+ num) + 10).trim());
						} else {
							pointMapValue = 10-Integer
									.parseInt(contextString
											.substring(
													contextString
															.indexOf("pointMap"
																	+ num) + 11)
											.trim()
											.substring(
													0,
													contextString
															.substring(
																	contextString
																			.indexOf("pointMap"
																					+ num) + 11)
															.trim().length() - 1));
						}

						LogUtil.e(pointMapValue);
						pointMap.put(num - 1, pointMapValue);
						break;

					} else {

						if (num < 10) {
							pointMapValue = 10-Integer.parseInt(contextString
									.substring(
											contextString.indexOf("pointMap"
													+ num) + 10,
											contextString.indexOf(",pointMap"
													+ (num + 1))).trim());
						} else {
							pointMapValue =10- Integer.parseInt(contextString
									.substring(
											contextString.indexOf("pointMap"
													+ num) + 11,
											contextString.indexOf(",pointMap"
													+ (num + 1))).trim());
						}

					}

				}
				pointMap.put(num - 1, pointMapValue);
				num++;
				index = contextString.indexOf("pointMap", index);
				LogUtil.e(pointMapValue);

			}
		}

		LogUtil.e(pointMap);

		// pointmaps
		pointMaps = new ArrayList<HashMap<String, Object>>();
		for (int i = 0; i < 40; i++) {
			HashMap<String, Object> itemHashMap = new HashMap<String, Object>();
			// x
			itemHashMap.put("x", i);
			// y
			itemHashMap.put("y", "");
			// 温度
			itemHashMap.put("temperature", "");
			// 时间
			itemHashMap.put("time", "");
			// DeltaT
			itemHashMap.put("deltaT", "");
			// gotTo
			itemHashMap.put("goTo", "");
			// Repititions
			itemHashMap.put("repititions", "");
			pointMaps.add(itemHashMap);

		}
		// 初始化
		mSimpleLineChart = BindView(R.id.simpleLineChart);

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
		mSimpleLineChart.setYItem(yItem);
		UpdateView();
	}

	public class RecyclerViewAdapter extends
			RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

		ArrayList<MethodBean> methodBeans = new ArrayList<MethodBean>();

		public RecyclerViewAdapter(ArrayList<MethodBean> methodBeans) {
			super();
			this.methodBeans = methodBeans;
		}

		class MyViewHolder extends
				android.support.v7.widget.RecyclerView.ViewHolder {

			TextView titleTv;
			LinearLayout orline, line;
			ImageView exitBtn;

			public MyViewHolder(View view) {
				super(view);
				// temperatureTv = (TextView) view
				// .findViewById(R.id.temperatureTv);
				// timeTv = (TextView) view.findViewById(R.id.timeTv);
				// deltaTTv = (TextView) view.findViewById(R.id.deltaTTv);
				line = (LinearLayout) view.findViewById(R.id.line);
				titleTv = (TextView) view.findViewById(R.id.titleTv);
				orline = (LinearLayout) view.findViewById(R.id.orline);
				exitBtn = (ImageView) view.findViewById(R.id.exitBtn);
			}
		}

		@Override
		public int getItemCount() {
			return methodBeans.size() >= 0 ? methodBeans.size() : 0;
		}

		@Override
		public int getItemViewType(int position) {

			if (position == methodBeans.size()) {
				return 0;
			}

			if ("step".equals(methodBeans.get(position).getSteptType())) {
				return 1;
			} else if ("solubilityCurve".equals(methodBeans.get(position)
					.getSteptType())) {
				return 2;
			}

			return 0;

		}

		@Override
		public void onBindViewHolder(final MyViewHolder holder,
				final int position) {
			final int index = position + 1;
			if (getItemViewType(position) == 1) {
				// holder.temperatureTv.setText(methodBeans.get(position)
				// .getTemperature());
				// holder.timeTv.setText(methodBeans.get(position).getTime());

				holder.titleTv.setText("Step" + index);

			} else if (getItemViewType(position) == 2) {
				// holder.temperatureTv.setText(methodBeans.get(position)
				// .getTemperature());
				// holder.timeTv.setText(methodBeans.get(position).getTime());
				// holder.deltaTTv.setText(methodBeans.get(position).getDeltaT());
				holder.titleTv.setText("Step" + index);

			} else {

			}

		}

		@Override
		public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
			if (viewType == 1) {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						getActivity()).inflate(
						R.layout.item_methods_step_title, parent, false));
				return holder;
			} else if (viewType == 2) {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						getActivity()).inflate(
						R.layout.item_methods_step_title, parent, false));
				return holder;
			} else {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						getActivity()).inflate(
						R.layout.item_methods_step_create_new, parent, false));
				return holder;
			}
		}
	}

	private void UpdateView() {

		switch (pointMap.size()) {
		case 0:
			xItem = new String[] { "" };
			break;
		case 1:
			xItem = new String[] { "Step1" };
			break;
		case 2:
			xItem = new String[] { "Step1", "", };
			break;
		case 3:
			xItem = new String[] { "Step1", "", "Step2" };
			break;
		case 4:
			xItem = new String[] { "Step1", "", "Step2", "" };
			break;
		case 5:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3" };
			break;
		case 6:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "" };
			break;

		case 7:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4" };
			break;
		case 8:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "" };
			break;
		case 9:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5" };
			break;
		case 10:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "" };
			break;
		case 11:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6" };
			break;
		case 12:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "" };
			break;
		case 13:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7" };
			break;
		case 14:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "" };
			break;
		case 15:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "", "Step8" };
			break;
		case 16:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "" };
			break;
		case 17:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9" };
			break;
		case 18:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "" };
			break;
		case 19:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10" };
			break;
		case 20:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "" };
			break;
		case 21:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11" };
			break;
		case 22:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "" };
			break;
		case 23:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12" };
			break;
		case 24:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "" };
			break;
		case 25:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13" };
			break;
		case 26:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "" };
			break;
		case 27:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14" };
			break;
		case 28:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "" };
			break;
		case 29:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15" };
			break;
		case 30:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "" };
			break;
		case 31:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16" };
			break;
		case 32:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "" };
			break;
		case 33:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17" };
			break;
		case 34:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "" };
			break;
		case 35:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18" };
			break;
		case 36:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "" };
			break;
		case 37:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19" };
			break;
		case 38:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "" };
			break;
		case 39:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "",
					"Step20" };
			break;
		case 40:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "",
					"Step20", "" };

			break;

		default:
			break;
		}
		mSimpleLineChart.setXItem(xItem);

		for (int i = 0; i < activityMethodBeans.size(); i++) {

			pointMaps.get(i).put("temperature",
					activityMethodBeans.get(i).getTemperature());
			pointMaps.get(i).put("time", activityMethodBeans.get(i).getTime());
			pointMaps.get(i).put("deltaT",
					activityMethodBeans.get(i).getDeltaT());
			pointMaps.get(i).put("gotTo", activityMethodBeans.get(i).getGoTo());
			pointMaps.get(i).put("repititions",
					activityMethodBeans.get(i).getRepititions());

		}

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
	}

	@Override
	public void onScrollChanged(MyHorizontalScrollView scrollView, int x,
			int y, int oldx, int oldy) {

		if (scrollView == downScrollView) {

			upScrollView.smoothScrollTo(x, 0);

		}
		if (scrollView == upScrollView) {
			downScrollView.smoothScrollTo(x, 0);

		}

	}

	/**
	 * 将view转换为图片保存
	 * 
	 * @param view
	 */
	public static String viewSaveToImage(View view) {
		String fileName = "";
		view.setDrawingCacheEnabled(true);
		view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
		// view.setDrawingCacheBackgroundColor(Color.WHITE);
		// 把一个View转换成图片
		Bitmap cachebmp = loadBitmapFromView(view);

		String imageName = "";

		// 添加水印
		Bitmap bitmap = Bitmap.createBitmap(cachebmp);

		FileOutputStream fos;
		try {
			// 判断手机设备是否有SD卡
			boolean isHasSDCard = Environment.getExternalStorageState().equals(
					android.os.Environment.MEDIA_MOUNTED);
			if (isHasSDCard) {
				// SD卡根目录
				long currentTimes = System.currentTimeMillis();
				File sdRoot = Environment.getExternalStorageDirectory();
				File file = new File(sdRoot,
						imageName.equals("") ? currentTimes + ".jpg"
								: imageName + ".jpg");
				fileName = sdRoot.getAbsolutePath()
						+ "/"
						+ (imageName.equals("") ? currentTimes + ".jpg"
								: imageName + ".jpg");
				fos = new FileOutputStream(file);
			} else {
				// Toast.makeText(MyApplication.ctx,
				// "save faile,create file fail", Toast.LENGTH_SHORT).show();
				throw new Exception("创建文件失败!");
			}
			bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);

			fos.flush();
			fos.close();

			// Toast.makeText(MyApplication.ctx, "save successs",
			// Toast.LENGTH_SHORT).show();
			// Logger.d("保存成功");
		} catch (Exception e) {
			e.printStackTrace();
		}
		imageName = "";
		view.destroyDrawingCache();
		return fileName;
	}

	public static Bitmap loadBitmapFromView(View v) {
		int w = v.getWidth();
		int h = v.getHeight();
		Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
		Canvas c = new Canvas(bmp);
		c.drawColor(Color.WHITE);
		c.save();
		// c.scale(0.5f, 0.5f);

		/** 如果不设置canvas画布为白色，则生成透明 */
		v.layout(0, 0, w, h);
		v.draw(c);
		return bmp;
	}
}
